﻿// <copyright file="IEnumerableExtensionsTest.cs" company="N/A">
//     Copyright (c) Nicholas Barrett and Benjamin Kasten.  All rights reserved.
//
//     This program is free software; you can redistribute it and/or modify it
//     under the terms of the GNU General Public License as published by the
//     Free Software Foundation; either version 2 of the License, or (at your
//     option) any later version.
//
//     This program is distributed in the hope that it will be useful, but
//     WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
//     Public License for more details.
//
//     You should have received a copy of the GNU General Public License along
//     with this program; if not, write to the Free Software Foundation, 
//     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// </copyright>

namespace BetterAzureTableStorage.Tests
{
    using System;
    using System.Collections.Generic;
    using BetterAzureTableStorage;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure;
    

    /// <summary>
    /// This is a test class for IEnumerableExtensionsTest and is intended
    /// to contain all IEnumerableExtensionsTest Unit Tests
    /// </summary>
    [TestClass()]
    public class IEnumerableExtensionsTest
    {

        [TestMethod()]
        public void SplitTest()
        {
            int splitLength = 124;
            int multiplier = 7;
            int remainder = 26;

            List<GenericParameterHelper> myListWithSmallSplitLength = new List<GenericParameterHelper>();
            List<GenericParameterHelper> myListWithLargeSplitLength = new List<GenericParameterHelper>();
            List<GenericParameterHelper> myListWithNoContent = new List<GenericParameterHelper>();

            for (int i = 0; i < (splitLength * multiplier) + remainder; i++)
            {
                myListWithSmallSplitLength.Add(new GenericParameterHelper(i));
                myListWithLargeSplitLength.Add(new GenericParameterHelper(i));
            }

            IList<IList<GenericParameterHelper>> splitLists = myListWithSmallSplitLength.Split<GenericParameterHelper>(splitLength);
            IList<IList<GenericParameterHelper>> splitListLargeSplitLength = myListWithLargeSplitLength.Split<GenericParameterHelper>(splitLength * 2 * multiplier);
            IList<IList<GenericParameterHelper>> splitListWithNoContent = myListWithNoContent.Split<GenericParameterHelper>(splitLength);

            Assert.AreEqual<int>(1, splitListLargeSplitLength.Count);
            Assert.AreEqual<int>(multiplier + 1, splitLists.Count);
            Assert.AreEqual<int>(0, splitListWithNoContent.Count);

            for (int i = 0; i < splitLists.Count; i++)
            {
                if (i == splitLists.Count - 1)
                {
                    Assert.AreEqual<int>(remainder, splitLists[i].Count);
                }
                else
                {
                    Assert.AreEqual<int>(splitLength, splitLists[i].Count);
                }
            }

            Assert.AreEqual<int>(multiplier * splitLength + remainder, splitListLargeSplitLength[0].Count);
        }
    }
}
